﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OABackground.Entities;
using OABackground.Infrastructure;
using OABackground.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace SchoolOA.Controllers
{
    public class ApiController : Controller
    {
        protected ZhenJiaoRepository zhenjiaoRepository = new ZhenJiaoRepository();
        protected LoginSevice loginsevice = new LoginSevice();
        protected IndexService indexservice = new IndexService();
        protected ZhenJiaoService zhenjiaoservice = new ZhenJiaoService();
        protected FileService fileService = new FileService();
        protected IndexRepository indexrepository = new IndexRepository();
        public class FileData
        {
            public int id;
            public string teacherName;
            public string filepath;
            public string filename;
            public string committime;
            public string state;
            public string issue;
        }
        public enum FileState
        {
            等待审核 = 0,
            已通过,
            等待修正,
            已修正,
            已驳回
        }
        public enum MaterialState
        {
            未处理 = 0,
            同意,
            拒绝,
        }
        public enum ConventionState
        {
            正在审核 = 0,
            通过申请,
            已被拒绝,
        }
        public class IndexData
        {
            public int allTeacher;
            public int allConvention;
            public int allAwardPunish;
            public int allStudent;
        }
        public IActionResult Index()
        {
            ApiController apiController = new ApiController();
            var type = apiController.GetType();
            var arrayMethodInfo = type.GetMethods();//所有的公有方法 22-63
            List<string> methodNameList = new List<string>() { };
            for (int i = 22; i < 63; i++)
            {
                methodNameList.Add(arrayMethodInfo[i].ToString());
            }
            
            return View(methodNameList);
        }
        public Dictionary<string, int> GetCountOfWhatINeed()
        {
            Dictionary<string, int> indexCountData = new Dictionary<string, int>() { };
            indexCountData.Add("meeting", indexrepository.QueryConventionapply().Count);
            indexCountData.Add("awardPunish", zhenjiaoRepository.QueryAwardPunish().Count);
            indexCountData.Add("teacher", zhenjiaoRepository.QueryAllTeacher().Count);
            indexCountData.Add("student", zhenjiaoRepository.QueryAllStudent().Count);
            return indexCountData;
        }
        public object LogInJudge(string username, string password, string type)
        {

            bool isVerifyPassword = loginsevice.VerifyPassword(username, password);
            if (!isVerifyPassword)
            {
                return Json(new
                {
                    code = 270,
                    msg = "账号密码不匹配"
                });
            }
            bool isMatchSection = loginsevice.VerifySection(username, type);
            if (!isMatchSection)
            {
                return Json(new
                {
                    code = 270,
                    msg = "请选择与您帐号匹配的部门"
                });
            }
            if (isVerifyPassword)
            {
                switch (type)
                {
                    case "js":
                    case "xz":
                    case "zjc":
                    case "cwc":
                        HttpContext.Session.SetString("username", username);
                        HttpContext.Session.SetString("section", type);
                        return Json(new
                        {
                            code = 200,
                            msg = "登录成功，正在跳转页面。。。"
                        });
                    default:
                        return Json(new
                        {
                            code = 100,
                            msg = "内部服务器错误"
                        });
                }
            }
            else
            {
                return Json(new
                {
                    code = 210,
                    msg = "密码与帐号不匹配。",
                });
            }
        }
        public object GetConventionApply(int page, int limit)
        {
            var conventionList = indexservice.QueryConventionapply();
            var showConventionList = conventionList.Skip((page - 1) * limit).Take(limit);
            return Json(new
            {
                code = 0,
                msg = "会议信息",
                count = conventionList.Count,
                data = showConventionList
            });
        }
        public object AwardPunishList(int page, int limit)
        {
            var awardPunishList = indexservice.QueryAwardPunish();
            var showAwardPunishList = awardPunishList.Skip((page - 1) * limit).Take(limit);
            return Json(new
            {
                code = 0,
                msg = "奖惩信息",
                count = awardPunishList.Count,
                data = showAwardPunishList
            });
        }
        public object ShowAwardPunishList(int id)
        {
            var awardPunishDetail = indexservice.QueryAwardPunishDetail(id);
            if (awardPunishDetail.punishContent == null)
            {
                return Json(new
                {
                    code = 0,
                    msg = "奖励信息",
                    awardDetail = awardPunishDetail
                });
            }
            return Json(new
            {
                code = 1,
                msg = "惩罚信息",
                punishDetail = awardPunishDetail
            });
        }
        public object ShowAwardList(string id)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            if (id == null)
            {
                return Json(new
                {
                    code = 280,
                    msg = "id为空，需要显示所有数据"
                });
            }
            var awardDetail = zhenjiaoservice.QueryAwardDetailBySid(id);
            if (awardDetail.Count == 0)
            {
                return Json(new
                {
                    code = 270,
                    msg = "按ID查询失败，错误请求"
                });
            }
            else
            {
                return Json(new
                {
                    code = 0,
                    msg = "按ID查询成功，所有奖励信息",
                    award = awardDetail,
                });
            }
        }
        public object ShowPunishList(string id)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            if (id == null)
            {
                return Json(new
                {
                    code = 280,
                    msg = "ID为空，需要显示所有数据",
                });
            }
            var punishDetail = zhenjiaoservice.QueryPunishDetailBySid(id);
            if (punishDetail.Count == 0)
            {
                return Json(new
                {
                    code = 270,
                    msg = "按ID查询失败，错误请求"
                });
            }
            else
            {
                return Json(new
                {
                    code = 0,
                    msg = "惩罚信息",
                    award = punishDetail,
                });
            }

        }
        public object AwardList(int page, int limit)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var awardDetail = zhenjiaoservice.QueryAllAwardDetail();
            var showAwardDetail = awardDetail.Skip((page - 1) * limit).Take(limit);
            return Json(new
            {
                code = 0,
                msg = "所有奖励信息",
                count = awardDetail.Count,
                data = showAwardDetail,
            });
        }
        public object PunishList(int page, int limit)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var punishDetail = zhenjiaoservice.QueryAllPunishDetail();
            var showPunishDetail = punishDetail.Skip((page - 1) * limit).Take(limit);
            return Json(new
            {
                code = 0,
                msg = "所有惩罚信息",
                count = punishDetail.Count,
                data = showPunishDetail,
            });
        }
        public object SubmitHandleAwardPunish(int id, string issue, string state)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            bool isSuccess = zhenjiaoservice.UpdateAwardPunish(id, issue, state);
            var updateDate = zhenjiaoservice.QueryPunishDetail(id);
            if (isSuccess)
            {
                return Json(new
                {
                    code = 0,
                    msg = "修改成功",
                    data = updateDate
                });
            }
            else
            {
                return Json(new
                {
                    code = 1,
                    msg = "修改失败",
                    data = updateDate
                });
            }
        }
        public object QueryFile(string teacherid, int page = 1, int limit = 10)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var fileData = fileService.QueryFile(teacherid).Skip((page - 1) * limit).Take(limit);
            List<FileData> fileDataList = new List<FileData>();
            foreach (var item in fileData)
            {
                var temData = new FileData();
                temData.id = item.Id;
                temData.teacherName = item.Teacherid;
                temData.filepath = item.Filepath;
                temData.filename = item.Filename;
                temData.committime = item.Committime.ToString().Replace('T', ' ');
                temData.state = ((FileState)item.State).ToString();
                fileDataList.Add(temData);
            }
            return Json(new
            {
                code = 0,
                msg = "查询成功",
                data = fileDataList
            });
        }
        public object QueryAllFile()
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var fileData = fileService.QueryAllFile();
            List<FileData> fileDataList = new List<FileData>();
            foreach (var item in fileData)
            {
                var teacher = zhenjiaoRepository.QueryTeacherById(item.Teacherid);
                var temData = new FileData();
                temData.id = item.Id;
                temData.teacherName = teacher.Tname;
                temData.filepath = item.Filepath;
                temData.filename = item.Filename;
                temData.committime = item.Committime.ToString().Replace('T', ' ');
                temData.state = ((FileState)item.State).ToString();
                fileDataList.Add(temData);
            }
            return Json(new
            {
                code = 0,
                msg = "查询成功",
                data = fileDataList
            });
        }
        public object QueryAllTeacher(int page, int limit)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var allTeacher = zhenjiaoservice.QueryAllTeacher();
            var showAllTeacher = allTeacher.Skip((page - 1) * limit).Take(limit);
            if (allTeacher.Count == 0)
            {
                return Json(new
                {
                    code = 270,
                    msg = "数据异常"
                });
            }
            else
            {
                return Json(new
                {
                    code = 0,
                    msg = "教职工信息",
                    count = allTeacher.Count,
                    data = showAllTeacher,
                });
            }
        }
        public object QueryBySection(string section)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            if (section == null)
            {
                return Json(new
                {
                    code = 280,
                    msg = "key值为空,需要所有的数据",
                });
            }
            var teacherFilterBySection = zhenjiaoservice.QueryTeacherBySection(section);
            if (teacherFilterBySection == null)
            {
                return Json(new
                {
                    code = 270,
                    msg = "数据不存在"
                });
            }
            return Json(new
            {
                code = 200,
                msg = "部门筛选信息",
                data = teacherFilterBySection
            });
        }
        public object QueryTeacher(string type, string key)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            if (key == null)
            {
                return Json(new
                {
                    code = 280,
                    msg = "key值为空,需要所有的数据",
                });
            }
            List<TeacherPassword> teacherList = new List<TeacherPassword>();
            if (type == "教师工号")
            {
                var teacher = zhenjiaoservice.QueryTeacherById(key);
                if (teacher.teacherId == null)
                {
                    return Json(new
                    {
                        code = 270,
                        msg = "查询失败"
                    });
                }
                else
                    teacherList.Add(teacher);
                return Json(new
                {
                    code = 200,
                    msg = "查询教职工信息成功",
                    data = teacherList
                });
            }
            else
            {
                var teacher = zhenjiaoservice.QueryTeacherByName(key);
                if (teacher.Count == 0)
                {
                    return Json(new
                    {
                        code = 270,
                        msg = "查询失败"
                    });
                }
                else
                    return Json(new
                    {
                        code = 200,
                        msg = "查询教职工信息成功",
                        data = teacher
                    });
            }
        }
        public object QueryAllMaterialApply(int page, int limit)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var materialApplyList = zhenjiaoservice.QueryMaterialDetail();
            var showMaterialApplyList = materialApplyList.Skip((page - 1) * limit).Take(limit);
            if (materialApplyList.Count == 0)
            {
                return Json(new
                {
                    code = 270,
                    msg = "数据异常"
                });
            }
            else
            {
                return Json(new
                {
                    code = 0,
                    msg = "查询成功",
                    count = materialApplyList.Count,
                    data = showMaterialApplyList,
                });
            }
        }
        public object ShowMaterialApply(int id)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var material = zhenjiaoservice.QueryMaterialById(id);
            if (material == null)
            {
                return Json(new
                {
                    code = 270,
                    msg = "按id查询物资信息失败"
                });
            }
            else
            {
                return Json(new
                {
                    code = 200,
                    msg = "按id查询物资信息成功",
                    materialDetail = material
                });
            }

        }
        public object SubmitHandleMaterialApply(int id, string state)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var updateMaterialState = zhenjiaoservice.UpdateMaterial((int)Enum.Parse(typeof(MaterialState), state), id);
            if (updateMaterialState)
            {
                return Json(new
                {
                    code = 0,
                    msg = "修改物资状态成功"
                });
            }
            else
            {
                return Json(new
                {
                    code = 270,
                    msg = "修改物资状态失败"
                });
            }

        }
        public object SubmitHandleConventionApply(int id, string state)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            var updateConvention = zhenjiaoservice.UpdateConvention((int)Enum.Parse(typeof(ConventionState), state), id);
            if (updateConvention)
            {
                return Json(new
                {
                    code = 0,
                    msg = "修改会议状态成功",
                });
            }
            else
            {
                return Json(new
                {
                    code = 270,
                    msg = "修改会议状态失败"
                });
            }
        }
        public object QueryMaterialByMaterialName(string materilName)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            if (materilName == null)
            {
                return Json(new
                {
                    code = 280,
                    msg = "name为空，查询失败,显示所有信息"
                });
            }
            var material = zhenjiaoservice.QueryMaterialByMaterialName(materilName);
            if (material.Count == 0)
            {
                return Json(new
                {
                    code = 270,
                    msg = "数据库无此name,查询失败"
                });
            }
            else
            {
                return Json(new
                {
                    code = 0,
                    msg = "按name查询成功",
                    data = material
                });
            }

        }
        public object QueryMaterialBySection(string section)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            if (section == null)
            {
                return Json(new
                {
                    code = 280,
                    msg = "section值为空,需要所有的数据",
                });
            }
            var materialFilterBySection = zhenjiaoservice.QueryMaterialDetailBySection(section);
            if (materialFilterBySection.Count == 0)
            {
                return Json(new
                {
                    code = 270,
                    msg = "数据不存在"
                });
            }
            else
            {
                return Json(new
                {
                    code = 200,
                    msg = "部门筛选信息",
                    data = materialFilterBySection
                });
            }
        }
        public object QueryConventionByPeopleName(string peopleName)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            if (peopleName == null)
            {
                return Json(new
                {
                    code = 270,
                    msg = "peopleName为空，无此ID"
                });
            }
            var convention = indexservice.QueryConventionByPeopleName(peopleName);
            if (convention.Count == 0)
            {
                return Json(new
                {
                    code = 280,
                    msg = "按peopleName查询失败"
                });
            }
            else
            {
                return Json(new
                {
                    code = 0,
                    msg = "按会议peopleName查询成功",
                    data = convention
                });
            }

        }
        public object ShowConvention(int id)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            if (id == 0)
            {
                return Json(new
                {
                    code = 270,
                    msg = "id为空，无此ID"
                });
            }
            var convention = indexservice.QueryConventionById(id);
            if (convention == null)
            {
                return Json(new
                {
                    code = 280,
                    msg = "按ID查询失败"
                });
            }
            else
            {

                return Json(new
                {
                    code = 200,
                    msg = "按会议ID查询成功",
                    conventionDetail = convention
                });
            }
        }
        /*校长 财务处*/
        public object QueryWorkPlan(string teacherid, uint state, int page, int limit)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            PlantableService plantableService = new PlantableService();
            var planList = plantableService.QueryWorkPlan(teacherid, state);
            var dataList = planList.Skip((page - 1) * limit).Take(limit);
            return Json(new
            {
                code = 200,
                msg = "WorkPlan query successfully!",
                count = planList.Count,
                data = dataList
            });
        }
        public object QueryWorkPlanbyID(int id)
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            PlantableService plantableService = new PlantableService();
            var plan = plantableService.QuerybyID(id);
            return Json(new
            {
                code = 200,
                msg = "WorkPlan query successfully!",
                plan = plan
            });
        }
        public object ReplyWorkPlan(int id, uint state, string issue)
        {
            PlantableService plantableService = new PlantableService();

            try
            {
                plantableService.ReplyWorkPlan(id, issue, state);
            }
            catch
            {
                return Json(new
                {
                    code = 270,
                    msg = "Plan status changed faild!",
                });
            }
            return Json(new
            {
                code = 200,
                msg = "Plan status changed successfully!",
            });
        }
        public object QueryMaterialApplication(int state, string departmentid)
        {
            MaterialapplyService materialapplyService = new MaterialapplyService();
            var materialapplyList = new List<Materialapply>();
            try
            {
                materialapplyList = materialapplyService.QuerybyDS(departmentid, state);
            }
            catch
            {
                return Json(new
                {
                    code = 270,
                    msg = "Material application query faild!",
                });
            }

            return Json(new
            {
                code = 0,
                count = materialapplyList.Count,
                msg = "Material application query successfully!",
                data = materialapplyList
            }) ;
        }
        public object QueryMaterialbyID(int id)
        {
            MaterialapplyService materialapplyService = new MaterialapplyService();
            var material = new Materialapply();
            try
            {
                material = materialapplyService.QuerybyID(id);
            }
            catch
            {
                return Json(new
                {
                    code = 270,
                    msg = "Query Material application faild!",
                });
            }

            return Json(new
            {
                code = 200,
                msg = "Query Material Application Successfully!",
                material = material
            });
        }
        public object HandleMaterialApplication(int id, int state)
        {
            MaterialapplyService materialapplyService = new MaterialapplyService();
            try
            {
                materialapplyService.Update(id, state);
            }
            catch
            {
                return Json(new
                {
                    code = 270,
                    msg = "Handle application faild!",
                });
            }

            return Json(new
            {
                code = 200,
                msg = "Handle application successfully!",
            });
        }
        public object QueryTeacherWage(string teacherid, string year, string month, string time)
        {
            WageService wageService = new WageService();
            try
            {
                var wageList = wageService.QueryTeacherWage(teacherid, year, month, time);
                if (wageList.Count != 0)
                {
                    return Json(new
                    {
                        code = 200,
                        msg = "Wage query successfully!",
                        wageList = wageList
                    });
                }
                return Json(new
                {
                    code = 270,
                    msg = "Wage query faild!",
                });
            }
            catch
            {
                return Json(new
                {
                    code = 270,
                    msg = "Wage query faild!",
                });
            }

        }
        public object QueryDepartmentWage(string departmentid, string time)
        {
            WageService wageService = new WageService();
            try
            {
                var wageList = wageService.QueryDepartmentWage2(departmentid, time);
                return Json(new
                {
                    code = 200,
                    msg = "Wage query successfully!",
                    wageList = wageList
                });
            }
            catch
            {
                return Json(new
                {
                    code = 270,
                    msg = "Wage query faild!",
                });
            }


        }
        public object UpdateWage(int id, float basicwage, float overtimewage, float welfare, float bonus)
        {
            WageService wageService = new WageService();
            try
            {
                wageService.UpdateWage(id, basicwage, overtimewage, welfare, bonus);
                return Json(new
                {
                    code = 200,
                    msg = "Wage update successfully!",
                });
            }
            catch
            {
                return Json(new
                {
                    code = 270,
                    msg = "Wage update faild!",
                });
            }

        }
        public object NewWage(string teacherid, string wagetime, float basicwage, float overtimewage, float welfare, float bonus)
        {
            WageService wageService = new WageService();
            try
            {
                wageService.AddWage(teacherid, wagetime, basicwage, overtimewage, welfare, bonus);
                return Json(new
                {
                    code = 200,
                    msg = "Add Wage successfully!",
                });
            }
            catch
            {
                return Json(new
                {
                    code = 270,
                    msg = "Add Wage faild!",
                });
            }

        }
        public object DeleteTeacherWage(int id)
        {
            WageService wageService = new WageService();
            try
            {
                wageService.DeleteWage(id);
                return Json(new
                {
                    code = 200,
                    msg = "delect Wage successfully!",
                });
            }
            catch
            {
                return Json(new
                {
                    code = 270,
                    msg = "delect Wage faild!",
                });
            }

        }

        /*教师*/
        public object TeacherInformation(string Tid)
        {
            var Teacher = new TeacherInformationService();
            var TeacherInfo = Teacher.QueryTeacherById(Tid);
            if (TeacherInfo != null)
            {
                return Json(new
                {
                    code = 200,
                    msg = "查询成功",
                    filelist = TeacherInfo
                });
            }
            else
            {
                return Json(new
                {
                    code = 250,
                    msg = "数据查询失败"
                });
            }
        }
        public object AddAwardPunishment2(string Title, string Sid, int PunishContent, string AwardContent, string Content)
        {
            var APT = new AwardPunishService();
            int Flag = APT.AddAwardPunishlist(Title, Sid, PunishContent, AwardContent, Content);
            if (Flag == -1)
            {
                return Json(new
                {
                    code = 270,
                    msg = "该学生不存在，请检查后重新输入"
                });
            }
            else if (Flag == 1)
            {
                return Json(new
                {
                    code = 200,
                    msg = "提交成功"
                });
            }
            else if (Flag == 0)
            {
                return Json(new
                {
                    code = 270,
                    msg = "申请标题为空，请填写"
                });
            }
            else if (Flag == 2)
            {
                return Json(new
                {
                    code = 270,
                    msg = "奖励内容不得为空，如果惩罚请填写“无”"
                });
            }
            else if (Flag == 3)
            {
                return Json(new
                {
                    code = 270,
                    msg = "请选择奖惩内容"
                });
            }
            else
            {
                return Json(new
                {
                    code = 270,
                    msg = "输入有错误！"
                });
            }
        }
        public object AddConventionapply2(string contact, string StartTime, string EndTime, string Conventionplace)
        {
            var ACA = new ConventionApplyService();
            int Flag = ACA.AddConventionApplyList(contact, StartTime, EndTime, Conventionplace);
            if (Flag == -1)
            {
                return Json(new
                {
                    code = 250,
                    msg = "联系人不得为空，请检查"

                });
            }
            else if (Flag == 0)
            {
                return Json(new
                {
                    code = 250,
                    msg = "会议时间不得为空，请检查"

                });
            }
            else if (Flag == 1)
            {
                return Json(new
                {
                    code = 250,
                    msg = "会议地点不得为空，请检查"

                });
            }
            else if (Flag == 2)
            {
                return Json(new
                {
                    code = 250,
                    msg = "会议时间冲突，请重新选择"

                });
            }
            else if (Flag == 3)
            {
                return Json(new
                {
                    code = 200,
                    msg = "提交成功"
                });

            }
            else
            {
                return Json(new
                {
                    code = 250,
                    msg = "输入有误！"

                });
            }

        }
        public object AddMaterialapply2(string Departmentid, string Tid, string Goodsname, int Goodsnum, float Goodsprice, string Remarks)
        {
            var AMA = new MaterialApplySubmitService();
            int Flag = AMA.AddMaterialApplyList(Departmentid, Tid, Goodsname, Goodsnum, Goodsprice, Remarks);
            if (Flag == -1)
            {
                return Json(new
                {
                    code = 270,
                    msg = "申请物资名称不得为空，请输入"

                });
            }
            else if (Flag == 0)
            {
                return Json(new
                {
                    code = 200,
                    msg = "提交成功"
                });
            }
            else if (Flag == 1)
            {
                return Json(new
                {
                    code = 270,
                    msg = "申请物资数量不得为空，请输入"

                });
            }
            else if (Flag == 2)
            {
                return Json(new
                {
                    code = 270,
                    msg = "申请单价不得为0，请输入"

                });
            }
            else if (Flag == 3)
            {
                return Json(new
                {
                    code = 270,
                    msg = "备注不得为空，如果没有请输入“无”"

                });
            }
            else
            {
                return Json(new
                {
                    code = 270,
                    msg = "请输入完整数据"

                });

            }
        }
        public object CheckAwardPunish()
        {
            var AwardPunish = new AwardPunishService();
            var APList = AwardPunish.QueryAwardPunishAll();
            if (APList != null)
            {
                return Json(new
                {
                    code = 200,
                    msg = "查询成功",
                    filelist = APList
                });
            }
            else
            {
                return Json(new
                {
                    code = 250,
                    msg = "数据查询失败"
                });
            }
        }
        public object CheckConventionByTid(string Tid)
        {
            var Tconvent = new ConventionApplyService();
            var TCLsit = Tconvent.QueryConventionByTid(Tid);
            if (TCLsit != null)
            {
                return Json(new
                {
                    code = 200,
                    msg = "查询成功",
                    filelist = TCLsit
                });
            }
            else
            {
                return Json(new
                {
                    code = 250,
                    msg = "数据查询失败"
                });
            }
        }
        public object CheckMaterialByTId(string Tid)
        {
            var Tmaterial = new MaterialApplySubmitService();
            var TMLsit = Tmaterial.QueryMaterialByTid(Tid);
            if (TMLsit != null)
            {
                return Json(new
                {
                    code = 200,
                    msg = "查询成功",
                    filelist = TMLsit
                });
            }
            else
            {
                return Json(new
                {
                    code = 250,
                    msg = "数据查询失败"
                });
            }
        }

        /*学生*/
        public object GetStudentName()
        {
            string name = HttpContext.Session.GetString("username");
            if (name == null)
            {
                return Redirect(Url.Action("ErrorPage", "Home"));
            }
            StudentService student = new StudentService();
            var nameList = student.GetManName();
            return Json(new
            {
                code = 200,
                msg = "执行完毕！"
            });
        }
    }
}